package org.dizem.minichat.util;

import com.sdicons.json.mapper.JSONMapper;
import com.sdicons.json.mapper.MapperException;
import com.sdicons.json.model.JSONValue;
import com.sdicons.json.parser.JSONParser;

import java.io.StringReader;

/**
 * User: DIZEM
 * Time: 11-3-25 上午12:49
 */
public class VOUtil {
	public static String convertVOTo2String(Object vo) {
		try {
			return JSONMapper.toJSON(vo).render(false);
		} catch (MapperException e) {
			throw new RuntimeException("Error when convert vo to string ");
		}
	}

	public static Object convertString2VO(String message, Class destClass) {
		try {
			JSONValue value = new JSONParser(new StringReader(message)).nextValue();
			return JSONMapper.toJava(value, destClass);
		} catch (Exception e) {
			e.printStackTrace();
		}
		return null;
	}
}
